<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="https://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js">
    </script>

    <link rel="stylesheet" href="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/css/bootstrap.min.css">

    <script src="https://cdn.staticfile.org/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <link rel="stylesheet"  th:href = "@{/plugins/xcConfirm/xcConfirm.css}">
    <script th:src = "@{/plugins/xcConfirm/xcConfirm.js}"></script>
    <style>
        .mytable{
            font-size: 16px;
            text-align: center;
        }
        .mytable th{
            text-align: center;
        }
    </style>
    <script>
        function getUrlParms(name){
            //获得页面url的某个url参数的方法
            var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
            var r = window.location.search.substr(1).match(reg);
            if(r!=null)
                return unescape(r[2]);
            return null;
        }
        var id = getUrlParms("rslt");
        // console.log(id);
        if(id=="0"){
            $(function () {
                var txt=  "没有每日一言，请尽快添加";
                // console.log(txt);
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
            })
        }
        if(id=="2"){
            $(function () {
                var txt=  "删除成功";
                // console.log(txt);
                window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
            })
        }
    </script>


</head>
<body>
<br>
<br>
<h4>&nbsp;&nbsp;&nbsp;&nbsp;共<span th:text="${total}"></span>条</h4>
<table class="table  mytable table-bordered">
    <thead>
    <tr>
        <td>时间</td>
        <td>名言</td>
        <td>作者</td>
        <td>操作</td>
    </tr>
    </thead>
    <tbody>
    <tr th:each="dayList:${dayList}">
        <td th:text="${#dates.format(dayList.createtime,'yyyy-MM-dd')}">前端</td>
        <td th:text="${dayList.day}">前端</td>
        <td th:text="${dayList.author}">前端</td>
        <td>
            <a th:href="@{'/admin/updateDay/'+${dayList.id}}" >
                <button class="btn btn-success" >修改</button>
            </a>
            <a id = "topBtn" th:if="${dayList.top ==0}">
                <button class="btn btn-success" th:onclick="'addTop('+${dayList.id}+')'">置顶</button>
            </a>
            <a id="noTopBtn" th:if="${dayList.top ==1}">
                <button class="btn btn-success"  th:onclick="'noTop('+${dayList.id} +')'">取消置顶</button>
            </a>
            <a id="deleteBtn">
                <button class="btn btn-warning" th:onclick="'deleteTag('+${dayList.id}+')'">删除</button>
            </a>
        </td>
        </td>
    </tr>
    </tbody>
</table>
<ul class="pagination">
    <li><a th:href="@{'/admin/day?pageNum='+${currPage-1}}">&laquo;</a></li>
    <li th:each="pageNum:${pages}">
        <a th:href="@{'/admin/day?pageNum='+${pageNum}}"th:classappend="${pageNum==currPage}?'active'"th:text="${pageNum}">1</a>
    </li>
    <li><a th:href="@{'/admin/day?pageNum='+${currPage+1}}">&raquo;</a></li>
</ul>

<!--删除-->
<!--删除-->
<script>
    function deleteTag(dayid){
        // console.log(tagid)
        var result = confirm("确认删除？")
        if (result){
            //删除
            // var tagid = $("#tagid").attr("value");
            $.ajax({
                url:"[(@{/admin/deleteTag})]",
                data:{"dayid":dayid},
                type:"post",
                success:function (measure) {
                    if (measure == "1"){
                        alert("删除成功");
                        window.location.href="[(@{/admin/day})]"
                    }
                }
            })
        }
    }
</script>


<!--取消置顶-->
<script>
    function noTop(dayid){
        var result = confirm("确认取消置顶？")
        if (result){
            //删除
            // var tagid = $("#noTopBtnid").attr("value");
            $.ajax({
                url:"[(@{/admin/noDayTop})]",
                data:{"dayid":dayid},
                type:"post",
                success:function (measure) {
                    if (measure == "1"){
                        //删除成功
                        alert("取消置顶成功")
                        window.location.href="[(@{/admin/day})]"
                    }
                    if (measure == "0"){
                        //删除成功
                        alert("无法取消置顶");
                        window.location.href="[(@{/admin/day})]"
                    }
                }
            })
        }
    }
</script>

<!--置顶-->
<script>
    function addTop(dayid){
        var result = confirm("确认置顶？")
        if (result){
            //删除
            // var tagid = $("#topBtnid").attr("value");
            $.ajax({
                url:"[(@{/admin/addDayTop})]",
                data:{"dayid":dayid},
                type:"post",
                success:function (measure) {
                    if (measure == "1"){
                        //删除成功
                        alert("置顶成功");
                        window.location.href="[(@{/admin/day})]"
                    }
                    if (measure == "0"){
                        //删除成功
                        $(function () {
                            var txt = "已经有了置顶，无法置顶";
                            // console.log(txt);
                            window.wxc.xcConfirm(txt, window.wxc.xcConfirm.typeEnum.error);
                        })
                        window.location.href="[(@{/admin/day})]"
                    }
                }
            })
        }
    }
</script>

</body>
</html>